import { Component } from "react";
import { ThemeContext } from "./contextCom"

class Child extends Component {
    constructor(props) {
        super(props)
        this.state = {
            age: 18
        }
    }
    render() {
        let theme = this.context;
        let props = this.props;
        return (
            <div style={{ backgroundColor: theme.background }} >
                {this.props.name}
               {props.changeTheme? <button onClick={props.changeTheme}>修改背景色</button>:""}
            </div>
        )
    }
}
Child.contextType = ThemeContext;
export default Child